// @ts-nocheck
import record from '@system.record';
import utils from '../helper/utils';

/**
 * 开始录音
 * @returns 
 */
const start = async () => {
    if(utils.isBrowser()) {
        return "browser://demo";
    }
    return new Promise((resolve, reject) => {
        record.start({
            duration: 1000 * 60, // 录音时长，单位为 ms。如果 duration 为有效值将在达到指定值时停止录音
            sampleRate: 16000,
            numberOfChannels: 1,
            // encodeBitRate: 16000,
            format: 'aac',
            success: function (data) {
                resolve(data.uri);
            },
            fail: function (data, code) {
                reject({ err_code: code, err_msg: data });
                // console.log(`handling fail, code = ${code}, errorMsg=${data}`)
            }
        })
    })
}

/**
 * 结束录音
 * @returns 
 */
const stop = () => {
    if(utils.isBrowser()) {
        return;
    }
    record.stop();
}

export default {
    start,
    stop
}